package cn.edu.tju.cas.service.impl;

import cn.edu.tju.cas.dao.BaseDao;
import cn.edu.tju.cas.service.BaseService;

import java.io.Serializable;
import java.util.List;

/**
 * Created by catold on 16/2/21.
 */
public abstract class BaseServcieImpl<T extends Serializable, D extends BaseDao<T>> implements BaseService<T> {
    private Class<T> clazz;
    private D dao;

    protected void setClass(final Class<T> clazz){
        this.clazz = clazz;
    }

    protected void setDao(final D dao) {
        this.dao = dao;
    }

    public T findById(final int id){
        return dao.findById(id);
    }

    public List<T> findAll(){
        return dao.findAll();
    }

    public void save(final T entity) {
        dao.save(entity);
    }

    public T update(T entity) {
        return dao.update(entity);
    }

    public void delete(final T entity) {
        dao.delete(entity);
    }

    public void deleteById(final int entityId) {
        dao.deleteById(entityId);
    }
}
